#include<QTest> 

#include"Song.h"
#include"TrPrRandom.h"

#include<time.h>

class TestTrPrRandom: public QObject{
Q_OBJECT
private:
	QList< QPointer<Song> > m_songs;
private slots:
	void initTestCase(){
		qsrand(time(0));
		qApp->setApplicationName("test");
		Song *song = new Song("song.ogg");
		m_songs.push_back(song);
		song = new Song("song.ogg");
		m_songs.push_back(song);
	}
	
	void cleanupTestCase(){
		while(m_songs.size())
			delete m_songs.takeAt(0);
	}
	
	void testRepeatOne(){
		TrPrRandom *trpr = new TrPrRandom(&m_songs, TrackProgression::RepeatOne);
		
		QCOMPARE(trpr->current(), -1);
		QVERIFY(trpr->next());
		int p = trpr->current();
		QVERIFY(trpr->next());
		QCOMPARE(trpr->current(), p);
		trpr->previous();
		QCOMPARE(trpr->current(), p);
		
		delete trpr;
	}
	
	void testNoRepeat(){
		TrPrRandom *trpr = new TrPrRandom(&m_songs, TrackProgression::NoRepeat);
		
		QCOMPARE(trpr->current(), -1);
		QVERIFY(trpr->next());
		int p = trpr->current();
		QVERIFY(trpr->next());
		QCOMPARE(trpr->current(), (p+1)%2);
		trpr->previous();
		QCOMPARE(trpr->current(), p);
		QVERIFY(trpr->next());
		QCOMPARE(trpr->current(), (p+1)%2);
		QVERIFY(trpr->next() == false);
		QCOMPARE(trpr->current(), -1);
		
		delete trpr;
	}
	
	void testRepeatAll(){
		TrPrRandom *trpr = new TrPrRandom(&m_songs, TrackProgression::RepeatAll);
		
		QCOMPARE(trpr->current(), -1);
		QVERIFY(trpr->next());
		int p = trpr->current();
		QVERIFY(trpr->next());
		QCOMPARE(trpr->current(), (p+1)%2);
		trpr->previous();
		QCOMPARE(trpr->current(), p);
		QVERIFY(trpr->next());
		QCOMPARE(trpr->current(), (p+1)%2);
		QVERIFY(trpr->next());
		QCOMPARE(trpr->current(), p);
		
		delete trpr;
	}
};

QTEST_MAIN(TestTrPrRandom);
#include"TestTrPrRandom.moc"
